package krt.wid.gslzs.adpater;

/**
 * Created by admin on 2018/5/10.
 */

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import krt.wid.gslzs.bean.Choose_BM;
import krt.wid.gslzs.R;

public class GridViewAdapter extends BaseAdapter {

    private List<Choose_BM> mList;
    private Context mContext;

    public GridViewAdapter(Context context, List<Choose_BM> list) {
        super();
        this.mContext = context;
        this.mList = list;
    }

    public void setList(List<Choose_BM> list) {
        mList = list;
        notifyDataSetChanged();
    }

    public List<Choose_BM> getList() {
        return mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Choose_BM getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ChildHolderOne holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_bumen, parent, false);
            holder = new ChildHolderOne();
            holder.DePname = convertView.findViewById(R.id.choose_bumen);
            convertView.setTag(holder);
        } else {
            holder = (ChildHolderOne) convertView.getTag();
        }
        Choose_BM gridInfo = mList.get(position);
        holder.DePname.setSelected(gridInfo.isSelect());
        holder.DePname.setText(gridInfo.getDepName());
        holder.DePname.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                holder.DePname.setSelected(!holder.DePname.isSelected());
                mList.get(position).setSelect(holder.DePname.isSelected());
//                if (mList.get(position).isSelect()){
//                    MToast.showToast(mContext,mList.get(position).getDepTypeName());
//                }
                notifyDataSetChanged();
            }
        });


        return convertView;
    }

    class ChildHolderOne {
        TextView DePname;
    }

}

